#include "continued_action.h"
#include "../node/sprite.h"
#include "../../base/obj_cache.h"

OPEN_JLIB_NS


void MoveTo::start () {
  ContinuedAction::start();
  auto node = (Node*)_target;
  _src = node->getPosition();
}
void MoveTo::apply (f32 progress) {
  auto node = (Node*)_target;
  node->setPosition(Vec3::lerp(_src, _dst, progress));
}
bool MoveTo::init (f32 duration, Vec3 to) {
  _dst = to;
  return ContinuedAction::init(duration);
}



void MoveBy::start () {
  MoveTo::start();
  _dst = _src + _delta;
}
bool MoveBy::init (f32 duration, Vec3 delta) {
  _delta = delta;
  return ContinuedAction::init(duration);
}
MoveBy* MoveBy::inverse () {
  return ObjCache::create<MoveBy>(duration(), -_delta);
}



void RotateTo::start () {
  ContinuedAction::start();
  auto node = (Node*)_target;
  _src = node->getRotation();
}
void RotateTo::apply (f32 progress) {
  auto node = (Node*)_target;
  node->setRotation(Vec3::lerp(_src, _dst, progress);
}
bool RotateTo::init (f32 duration, Vec3 to) {
  _dst = to;
  return ContinuedAction::init(duration);
}



void RotateBy::start () {
  RotateTo::start();
  _dst = _src + _delta;
}
bool RotateBy::init (f32 duration, Vec3 delta) {
  _delta = delta;
  return ContinuedAction::init(duration);
}
RotateBy* RotateBy::inverse () {
  return ObjCache::create<RotateBy>(duration(), -_delta);
}



void ScaleTo::start () {
  ContinuedAction::start();
  auto node = (Node*)_target;
  _src = node->getScale();
}
void ScaleTo::apply (f32 progress) {
  auto node = (Node*)_target;
  node->setScale(Vec3::lerp(_src, _dst, progress));
}
bool ScaleTo::init (f32 duration, Vec3 to) {
  _dst = to;
  return this->ContinuedAction::init(duration);
}



void ScaleBy::start () {
  ScaleTo::start();
  _dst = _src + _delta;
}
bool ScaleBy::init (f32 duration, Vec3 delta) {
  _delta = delta;
  return ContinuedAction::init(duration);
}
ScaleBy* ScaleBy::inverse () {
  return ObjCache::create<ScaleBy>(duration(), -_delta);
}



void Animate::start () {
  ContinuedAction::start();
  auto sprite = (Sprite*)_target;
  image->set
}


CLOSE_JLIB_NS

